package com.ks.pc.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ks.dto.BrandDto;
import com.ks.dto.ClassifyDto;
import com.ks.dto.ImgDto;
import com.ks.dto.OtherDto;
import com.ks.dto.ProductDto;
import com.ks.pc.service.SysBannerService;
import com.ks.pc.service.SysOtherService;
import com.ks.pc.service.SysUeditorService;

/**
 * 后面所有跳转
 * 
 * @author jxzhang on 2017年3月16日
 * @Verdion 1.0 版本
 */
@Controller
@RequestMapping("/sys")
public class SysController {

	@Autowired
	private SysBannerService sysBannerService;
	@Autowired
	private SysUeditorService sysUeditorService;
	@Autowired
	private SysOtherService sysOtherService;

	/**
	 * 后台首页 </br>
	 * 调用sysMain.jsp
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/home", method = RequestMethod.GET)
	public String sysHomeView(Model model) {
		return "biz/sysHome";
	}

	/**
	 * 建设中
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("/buildingView")
	public String buildingView(Model model) {
		return "error/building";
	}

	// 系统管理
	// =============================================
	/**
	 * 系统管理-网站信息
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/infoView", method = RequestMethod.GET)
	public String sysInfoView(Model model) {
		OtherDto otherDto = sysOtherService.findOtherById(2);
		if (null != otherDto) {
			model.addAttribute(otherDto);
		}
		return "biz/sysInfo";
	}

	/**
	 * 系统管理-系统管理
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/mgrView", method = RequestMethod.GET)
	public String sysMgrView(Model model) {
		return "biz/sysMgr";
	}

	// 产品世界
	// =============================================
	/**
	 * 产品世界-产品设置
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/productView", method = RequestMethod.GET)
	public String sysProductView(Model model) {
		return "biz/sysProduct";
	}

	/**
	 * 产品世界-产品管理
	 * 
	 * @param model
	 * @param brandId
	 * @return
	 */
	@RequestMapping(value = "/productItemView", method = RequestMethod.GET)
	public String productItemView(Model model, Integer brandId) {
		model.addAttribute("brandId", brandId);
		return "biz/sysProductItem";
	}

	/**
	 * 产品世界-产品编辑
	 * 
	 * @param request
	 * @param productId
	 * @param brandId
	 * @return
	 */
	@RequestMapping(value = "/editView", method = RequestMethod.GET)
	public String editView(HttpServletRequest request, Integer productId, Integer brandId) {
		ProductDto productDto = new ProductDto();
		if (null != productId) {
			request.setAttribute("productId", productId);
			productDto = sysUeditorService.queryProductById(productId);
			// request.setAttribute("name", productDto.getName());
			// request.setAttribute("price", productDto.getPrice());
			// request.setAttribute("downpayment", productDto.getDownPayment());
			// request.setAttribute("monthlyPrice",
			// productDto.getMonthlyPayment());
			// request.setAttribute("cpu", productDto.getCpu());
			// request.setAttribute("ram", productDto.getRam());
			// request.setAttribute("rom", productDto.getRom());
			// request.setAttribute("resolution", productDto.getResolution());
			// request.setAttribute("screenSize", productDto.getScreenSize());
			// request.setAttribute("camera", productDto.getCamera());
			// request.setAttribute("card", productDto.getCard());
			// request.setAttribute("network", productDto.getNetwork());
			// request.setAttribute("time", productDto.getTime());
			// request.setAttribute("sort", productDto.getSort());
			// request.setAttribute("release", productDto.getHasPublic());
			// request.setAttribute("recommend", productDto.getRecommend());
			// request.setAttribute("content", productDto.getContent());
			// request.setAttribute("imgId", productDto.getImgId());
			// request.setAttribute("imgDtos", productDto.getImgDtos());
		}
		request.setAttribute("productDto", productDto);
		if (null == brandId)
			brandId = 26;
		BrandDto brandDto = sysUeditorService.queryBrandById(brandId);
		request.setAttribute("brandId", brandDto.getId());
		request.setAttribute("brandName", brandDto.getName());

		// request.setAttribute("pName", name);
		// request.setAttribute("price", price);
		// request.setAttribute("downPayment", downPayment);
		// request.setAttribute("monthlyPayment", monthlyPayment);
		return "biz/ueditor/edit";
	}

	/**
	 * 产品世界-横幅设置
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/bannerView", method = RequestMethod.GET)
	public String sysBannerView(Model model) {
		List<ImgDto> imgDtos = sysBannerService.findSlidePhoto();
		if (null == imgDtos)
			imgDtos = new ArrayList<ImgDto>();
		List<ClassifyDto> classifyDtos = sysUeditorService.queryAllClassify();
		if (null == classifyDtos)
			classifyDtos = new ArrayList<ClassifyDto>();
		model.addAttribute("classifyDtos", classifyDtos);
		model.addAttribute("imgDtos", imgDtos);
		return "biz/sysBanner";
	}

	// 其它设置
	// =============================================
	/**
	 * 其它设置-关于
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/aboutView", method = RequestMethod.GET)
	public String sysAboutView(Model model) {
		OtherDto otherDto = sysOtherService.findOtherById(1);
		if (null != otherDto) {
			model.addAttribute(otherDto);
		}
		return "biz/sysAbout";
	}

	/**
	 * 其它设置-办理条件
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/contactView", method = RequestMethod.GET)
	public String sysContactView(Model model) {
		OtherDto otherDto = sysOtherService.findOtherById(2);
		if (null != otherDto) {
			model.addAttribute(otherDto);
		}
		return "biz/sysContact";
	}

	/**
	 * 其它设置-预约客户列表
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/onlineOptView", method = RequestMethod.GET)
	public String onlineOptView(Model model, HttpServletRequest request) {
		return "biz/sysOnlineOpt";
	}

	/**
	 * 其它设置-品牌,商品排序页
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/orderByView", method = RequestMethod.GET)
	public String orderByView(Model model) {
		return "biz/orderBy";
	}

	/**
	 * 其它设置-商品排序页
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/orderByProductView", method = RequestMethod.GET)
	public String orderByProductView(Model model) {
		return "biz/orderByProduct";
	}
}
